﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cataloger
{
    public partial class FrmStanNosnikow : Form
    {
        private ListViewColumnSorterNosniki lvwColumnSorter;
        public FrmStanNosnikow()
        {
            InitializeComponent();
            lvwColumnSorter = new ListViewColumnSorterNosniki();
            this.listView1.ListViewItemSorter = lvwColumnSorter;
        }

        private void FrmStanNosnikow_Load(object sender, EventArgs e)
        {
            foreach (Katalog kat in Katalog.WczytaneKatalogi)
            {
                foreach (Nosnik n in kat.Nosniki)
                {
                    listView1.Items.Add(new ListViewItem(new string[] {kat.Nazwa,n.NazwaAlias,n.Status.ToString(),n.DataDodania.ToShortDateString(),n.RaportSkan.RozmiarZeskanowany.ToProperUnit(),n.RodzajDysku.ToString(),n.RaportSkan.IleFolderow.ToString(),n.RaportSkan.IlePlikow.ToString(),n.NrSeryjny,n.CzyPodlaczony().ToString() }));
                }
            }
            toolStripStatusLabel1.Text = "Ilosc nośników: " + listView1.Items.Count.ToString();
        }

        private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            // Determine if clicked column is already the column that is being sorted.
            if (e.Column == lvwColumnSorter.SortColumn)
            {
                // Reverse the current sort direction for this column.
                if (lvwColumnSorter.Order == SortOrder.Ascending)
                {
                    lvwColumnSorter.Order = SortOrder.Descending;
                }
                else
                {
                    lvwColumnSorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                lvwColumnSorter.SortColumn = e.Column;
                lvwColumnSorter.Order = SortOrder.Ascending;
            }

            // Perform the sort with these new sort options.
            this.listView1.Sort();

        }
    }
}
